// 折线图X轴数据
var polygonalXData = ['2012', '2013', '2014', '2015', '2016'];
//折线图 放款金额
var loanData = [1000, 332, 301, 334, 390];
//折线图 还款金额
var repayment = [220, 182, 191, 234, 290];
//折线图 续期金额
var renewal = [150, 232, 201, 154, 190];
//折线图 待还金额
var Remain = [98, 77, 101, 99, 40];
//折线图 逾期金额
var overdue =[98, 77, 101, 99, 40];
//圆环图 复贷人数
var doubleLoan = 15;
//圆环图 贷款人数
var loanPersonNum = 20;



var doubleLoanRate = parseInt((doubleLoan/loanPersonNum)*100);


var dom = document.getElementById("container");
var myChart = echarts.init(dom);
var app = {};
option = null;
var posList = [
    'left', 'right', 'top', 'bottom',
    'inside',
    'insideTop', 'insideLeft', 'insideRight', 'insideBottom',
    'insideTopLeft', 'insideTopRight', 'insideBottomLeft', 'insideBottomRight'
];

app.configParameters = {
    rotate: {
        min: -90,
        max: 90
    },
    align: {
        options: {
            left: 'left',
            center: 'center',
            right: 'right'
        }
    },
    verticalAlign: {
        options: {
            top: 'top',
            middle: 'middle',
            bottom: 'bottom'
        }
    },
    position: {
        options: echarts.util.reduce(posList, function (map, pos) {
            map[pos] = pos;
            return map;
        }, {})
    },
    distance: {
        min: 0,
        max: 100
    }
};

app.config = {
    rotate: 90,
    align: 'left',
    verticalAlign: 'middle',
    position: 'insideBottom',
    distance: 15,
    onChange: function () {
        var labelOption = {
            normal: {
                rotate: app.config.rotate,
                align: app.config.align,
                verticalAlign: app.config.verticalAlign,
                position: app.config.position,
                distance: app.config.distance
            }
        };
        myChart.setOption({
            series: [{
                label: labelOption
            }, {
                label: labelOption
            }, {
                label: labelOption
            }, {
                label: labelOption
            }]
        });
    }
};


var labelOption = {
    normal: {
        // show: true,
        // position: app.config.position,
        // distance: app.config.distance,
        // align: app.config.align,
        // verticalAlign: app.config.verticalAlign,
        // rotate: app.config.rotate,
        // formatter: '{c}  {name|{a}}',
        // fontSize: 16,
        // rich: {
        //     name: {
        //         textBorderColor: '#fff'
        //     }
        // }
    }
};

option = {
    grid : {
        // left : 50,    //距离容器上边界40像素
        //距离容器下边界30像素
    },
    color: ['#958BFF', '#25C89A', '#4EA0FF', '#F7BB44','#F74466'],

    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'shadow'
        }
    },
    legend: {

        y:'bottom',
        data: [{name:'放款金额',icon: "circle"}, {name:'还款金额',icon: "circle"}, {name:'续期金额',icon: "circle"}, {name:'待还金额',icon: "circle"},{name:'逾期金额',icon: "circle"}],

    },

    calculable: true,
    xAxis: [
        {
            type: 'category',
            axisTick: {show: false},
            data: polygonalXData
        }
    ],
    yAxis: [
        {
            type: 'value'
        }
    ],
    series: [
        {
            name: '放款金额',
            type: 'bar',
            barGap: 0,
            data: loanData
        },
        {
            name: '还款金额',
            type: 'bar',
            data: repayment

        },
        {
            name: '续期金额',
            type: 'bar',
            data: renewal
        },
        {
            name: '待还金额',
            type: 'bar',
            data: Remain
        },
        {
            name: '逾期金额',
            type: 'bar',
            data: overdue
        }
    ]
};
if (option && typeof option === "object") {
    myChart.setOption(option, true);
}

var dom = document.getElementById("circle");
var myChart = echarts.init(dom);
var app = {};
option = null;
app.title = '环形图';

option = {
    color:['#4EA0FF','#cacaca'],

    graphic:{       //图形中间文字
        type:"text",
        left:"center",
        top:"center",
        style:{
            text:"复贷率"+doubleLoanRate+"%",
            textAlign:"center",
            fill:"#080808",
            fontSize:15
        }
    },


    series: [
        {
            name:'访问来源',
            type:'pie',
            hoverAnimation:false,
            radius: ['75%', '100%'],
            avoidLabelOverlap: false,
            label: {
                normal: {
                    show: false,
                    position: 'center'
                },
                emphasis: {
                    show: false,
                    textStyle: {
                        fontSize: '30',
                        fontWeight: 'bold'
                    }
                }
            },
            labelLine: {
                normal: {
                    show: false
                }
            },
            data:[
                {value:doubleLoan, name:'复贷人数'},
                {value:loanPersonNum-doubleLoan, name:'无复人数'},
            ]
        }
    ]
};
;
if (option && typeof option === "object") {
    myChart.setOption(option, true);
}
